package Server;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerInitClose {

    private ServerSocket ss = null;
    private Socket s =null;
    private ObjectInputStream in =null;
    private ObjectOutputStream out = null;

    public ObjectInputStream getIn() {
        return in;
    }

    public ObjectOutputStream getOut() {
        return out;
    }
    /**
     * description:服务器初始化
     * @return void
     */
    public void serverInit() throws IOException {

        ss = new ServerSocket(8888);
        System.out.println("等待客户端连接：");
        s = ss.accept();
        System.out.println("客户端连接成功！");
        in = new ObjectInputStream(s.getInputStream());
        out = new ObjectOutputStream(s.getOutputStream());
        System.out.println("初始化成功！");
    }
    /**
     * description:关闭服务器所有资源
     * @return void
     */
    public void serverclose() throws IOException {
        out.close();
        in.close();
        s.close();
        ss.close();
        System.out.println("服务器关闭成功！");
    }

}
